<?php
session_start();
if(!ob_start("ob_gzhandler")) ob_start();
$_SESSION['jalbum'] = $_REQUEST['album'];
?>
<html>
	<head>
		<title>Album</title>
		<script type="text/javascript" src="jquery-1.7.js"></script>
		<link rel="stylesheet" type="text/css" href="previewStyle.css">
		<script type="text/javascript" src="jquery-ui-1.8.16.custom.min.js"></script>
		<link rel = "stylesheet" type = "text/css" href = "jquery-ui-1.8.18.custom.css">
		<script type = "text/javascript" src = "izplushti.js"></script>
		<link rel = "stylesheet" type = "text/css" href = "mainFrame.css">
	</head>
	<body>
	<?php
		mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
		mysql_select_db("sapmenet_users");
		if(isset($_SESSION['JID'])){
		$userID=$_SESSION['JID'];
		$currentID=$_SESSION['id'];
		$_SESSION['jalbum']=$_REQUEST['album'];
		$ownerID=mysql_query("SELECT userID FROM albums WHERE ID={$_SESSION['jalbum']}");
		if (mysql_num_rows($ownerID)<1)
		{
			//psyvai
		}
		else
		{
			$ownerID=mysql_result($ownerID,0);
			if ($ownerID==$userID)
			{	
		echo("<center><div id = 'openUpload'><img src = 'upload-buttons(1).png'></div></center><div id='uploadForm' title = 'Upload Picture'>
			<form action='uploadPic.php' method='post' id='uploadFormPic' enctype='multipart/form-data'>
				Upload picture: <input type='file' name='uploadPic'/><br>
				Set as album cover: <input type='checkbox' name='makeCover'/><br>
				<input type='submit' value='Upload'/><br>
			</form>
		</div>
		<script>
			$('#uploadForm').dialog({autoOpen: false, width: 380, show: 'explode', hide: 'explode', modal: true});
			$('#openUpload').click(function()
			{
				$('#uploadForm').dialog('open')
			});
		</script>");
			}
		}
		$fr=mysql_query("SELECT confirmed FROM friendships WHERE userID={$_SESSION['JID']} AND friendID={$ownerID}");
		if (mysql_num_rows($fr)<1&&$userID!=$ownerID)
		{
			//PSYVAI
			
		}
		else{
		if (mysql_num_rows($fr)>1)
		{
		$fr=mysql_result($fr,0);
		}
		if ($fr ||$userID==$ownerID){
		echo "<center><div id='box'>
			<div id = 'navButs'><div id='prevPic' style='float:left;'><img src='leftArrow.png' style = 'cursor:pointer'></div><div id='nexPic' style='float:right'><img src = 'rightArrow.png' style = 'cursor:pointer;'></div></div><br>
			<div id='pliosPictureDiv'></div><div id='picture'>";
		echo"</div><div id = 'theCommentsDialog'><div id='commentsHeader'><h3>Comments</h3><img src='Icons/close.png' id='closeComments'></div><div id = 'commentsDialog'></div></div>
			</center>";
			echo"<script>
				$('#theCommentsDialog').hide();
				var pia = new Array(); 
				var position = 0;
				var picturesString;
				var theLength;
				$.post('showPicture.php', function(data)
				{
					picturesString = data;
					pia = picturesString.split(',');
					if(pia.length<1)
					{
						$('#picture').html('There are no pictures in this album. Let the force be with you.');
					}
					else
					{
						$.include('showPicture.js');
					}
				});
				$('.addCommentButton').click(function()
				{
					$.post('showComments.php', {snID : pia[curPic]}, function(data)
					{
						$('#commentsDialog').html(data);
					});
				});
			</script>";
			}
			else
			{
				
				//psyvaaiiii
			}
		}	
		}
		?>
		

	</body>
</html>